<?php

namespace App\Http\Controllers;

use App\KLine;
use Illuminate\Http\Request;

class StockController extends Controller
{

    public function index(Request $request)
    {
        switch ($request->type) {
            case 'plan1':
                $data = KLine::all()->map(function ($item) {
                    return [
                        //date
                        $item->date->format('Y/m/d'),
                        // open
                        (float)$item->open,
                        // close
                        (float) $item->close,
                        // lowest
                        (float)$item->lowest,
                        //'highest'
                        (float)$item->highest,
                    ];
                })->values()->toArray();
                break;
            case 'plan2':
                // ...
                break;
            default:
                $data = KLine::all()->toArray();
                break;
        }
        return view('stocks.index', [
            'data' => $data,
        ]);
    }
}
